define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'jubao/wcn/index' + location.search,
                    add_url: 'jubao/wcn/add',
                    edit_url: 'jubao/wcn/edit',
                    del_url: 'jubao/wcn/del',
                    multi_url: 'jubao/wcn/multi',
                    import_url: 'jubao/wcn/import',
                    table: 'jubao_wcn',
                }
            });

            var table = $("#table");
            var initstatus = true;//状态初始化
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                queryParams:function(params){
                    filter = JSON.parse(params.filter);
                    op = JSON.parse(params.op);
                    if(initstatus && !filter.status){
                        filter.status = Config.status ;//默认待处理
                        op.status = '=';
                        params.filter = JSON.stringify(filter);
                        params.op = JSON.stringify(op);
                    }
                    initstatus = false;
                    return params;
                },
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'no', title: __('No'), operate: 'LIKE'},
                        {field: 'type', title: __('Type'), searchList: {"personal":__('Type personal'),"company":__('Type company')}, formatter: Table.api.formatter.normal},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'id_card', title: __('Id_card'), operate: 'LIKE'},
                        {field: 'address', title: __('Address'), operate: 'LIKE'},
                        {field: 'r_type', title: __('R_type'), searchList: {"personal":__('R_type personal'),"company":__('R_type company')}, formatter: Table.api.formatter.normal},
                        {field: 'r_name', title: __('R_name'), operate: 'LIKE'},
                        {field: 'r_sex', title: __('R_sex'), searchList: {"0":__('R_sex 0'),"1":__('R_sex 1'),"2":__('R_sex 2')}, formatter: Table.api.formatter.normal},
                        {field: 'r_job', title: __('R_job'), operate: 'LIKE'},
                        {field: 'r_phone', title: __('R_phone'), operate: 'LIKE'},
                        {field: 'r_address', title: __('R_address'), operate: 'LIKE'},
                        {field: 'r_birthplace', title: __('R_birthplace'), operate: 'LIKE'},
                        {field: 'f_address', title: __('F_address'), operate: 'LIKE'},
                        {field: 'f_starttime', title: __('F_starttime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY"},
                        {field: 'f_endtime', title: __('F_endtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY"},
                        {field: 'f_isgang', title: __('F_isgang'), searchList: {"0":__('F_isgang 0'),"1":__('F_isgang 1'),"2":__('F_isgang 2')}, formatter: Table.api.formatter.normal},
                        //{field: 'f_money', title: __('F_money'), operate: 'LIKE'},
                        {field: 'f_num', title: __('F_num'), searchList: {"0":__('F_num 0'),"1":__('F_num 1'),"2":__('F_num 2'),"4":__('F_num 4'),"11":__('F_num 11'),"50":__('F_num 50')}, formatter: Table.api.formatter.normal},
                        {field: 'f_type', title: __('F_type'), searchList: {"1":__('F_type 1'),"2":__('F_type 2'),"3":__('F_type 3'),"4":__('F_type 4'),"5":__('F_type 5'),"6":__('F_type 6'),"7":__('F_type 7')}, operate:'FIND_IN_SET', formatter: Table.api.formatter.label},
                        {field: 'f_content', title: '基本案情', operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3')}, formatter: Table.api.formatter.status},
                        {field: 'remarks', title: __('Remarks'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime,datetimeFormat:"YYYY-MM-DD"},
                        //{field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
